
class Keyboard {
    static mapping_key_pressed: number[] = []; //touche qui sont active
    static mapping_touche: number[] = []; //mapping touche <=> actions
    static action: any = { dpl_gauche: 1, dpl_droite: 2, dpl_saut: 3, courir: 4 };

    static init() {
        //var action = 
        var dpl_gauche = $("#command #gauche").val();
        var dpl_droite = $("#command #droite").val();
        var dpl_saut = /*$("#command #saut").val()*/ " ";//espace
        var courir = 16;//maj
        console.log(courir);

        var mapping_touche = [];
        Keyboard.mapping_touche[dpl_gauche.toUpperCase().charCodeAt(0)] = Keyboard.action.dpl_gauche ;
        Keyboard.mapping_touche[dpl_gauche.toLowerCase().charCodeAt(0)] = Keyboard.action.dpl_gauche;
        Keyboard.mapping_touche[dpl_droite.toUpperCase().charCodeAt(0)] = Keyboard.action.dpl_droite;
        Keyboard.mapping_touche[dpl_droite.toLowerCase().charCodeAt(0)] = Keyboard.action.dpl_droite;
        Keyboard.mapping_touche[dpl_saut.toUpperCase().charCodeAt(0)] = Keyboard.action.dpl_saut;
        Keyboard.mapping_touche[dpl_saut.toLowerCase().charCodeAt(0)] = Keyboard.action.dpl_saut;
        Keyboard.mapping_touche[courir] = Keyboard.action.courir;
    }

    static keydown(evt) {
        Keyboard.mapping_key_pressed[evt.keyCode] = evt.keyCode;
        //console.log("pressed", evt.keyCode);
        /*switch (Keyboard.mapping_touche[evt.keyCode]) {
            case Keyboard.action.dpl_gauche:
                if (player.speed_mouvement == Player.STAND)
                    player.walkAnimation();
            break;

            case Keyboard.action.dpl_droite:
                if (player.speed_mouvement == Player.STAND)
                    player.walkAnimation();
            break;
        }*/
    }

    //liberation des touches
    static keyup(evt) {
        delete Keyboard.mapping_key_pressed[evt.keyCode];
        //console.log("unpressed", evt.keyCode);
        switch (Keyboard.mapping_touche[evt.keyCode]) {
            case Keyboard.action.courir: player.standAnimation(); break;
            case Keyboard.action.dpl_gauche: player.standAnimation(); break;
            case Keyboard.action.dpl_droite: player.standAnimation(); break;
        }

    }
}